//
//  AddDataView.m
//  DailyRecord
//
//  Created by Gin on 2022/3/29.
//

#import "AddDataView.h"

@interface AddDataView()

@property (nonatomic, strong) UIButton *addBtn;

@property (nonatomic, strong) UILabel *infoLb;

@end

@implementation AddDataView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (void)initUI{
    [self addSubview:self.infoLb];
    [self addSubview:self.addBtn];
}

- (void)setUpContraints{
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.infoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.addBtn.mas_bottom).offset(kBottomSpace);
    }];
}

- (Boolean)isAddCategory {
    return self.type == AddDataViewTypeCategory;
}

#pragma mark -- setter&&getter

- (UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [UIButton new];
        [_addBtn setImage:[UIImage imageNamed:@"tianjia"] forState:UIControlStateNormal];
        @weakify(self);
        [[_addBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self addData];
        }];
    }
    return _addBtn;
}

- (UILabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [UILabel new];
        _infoLb.font = kDescFont;
    }
    return _infoLb;
}

- (void)setType:(AddDataViewType)type{
    _type = type;
    _infoLb.text = type == AddDataViewTypeCategory ? @"暂无数据, 请先添加分类数据" : @"暂无数据, 请先添加记录数据";
}

@end
